package com.point.common.util;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author wangyh
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class RegexpUtil {
    /**
     * The constant STRING_NULL.
     */
    private final static String STRING_NULL = "-";

    /**
     * 匹配邮箱帐号
     */
    private static final String REG_EXP_EMAIL = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";

    /**
     * 校验手机号码是否合法.
     *
     * @param mobile the mobile
     * @return the boolean
     */
    public static boolean isMobileNumber(final String mobile) {
        if (StringUtils.isEmpty(mobile)) {
            return false;
        }
        final String reg = "^((\\+?86)|(\\(\\+86\\)))?(1[3-9][0-9]{9})$";
        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(mobile);
        return matcher.matches();
    }

    /**
     * Is email boolean.
     *
     * @param str the str
     * @return the boolean
     */
    public static boolean isEmail(String str) {
        if (!StringUtils.isNotEmpty(str) && str.matches(REG_EXP_EMAIL)) {
            return Boolean.TRUE;
        }

        return Boolean.FALSE;
    }


}
